package com.bridgeintelligent.tag.mapper;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimCatalog;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimData;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.model.DimNumModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by JackCheung on 2019/9/10 3:00 PM.
 */
@Mapper
public interface DimMapper {

    /**
     * 查询标签详情
     *
     * @param dimId
     * @return
     */
    DimData detail(@Param("dimId")String dimId);
    DimData detailHistory(@Param("dimId")String dimId);

    /**
     * 根据标签名查找标签是否存在
     *
     * @param dimName
     * @return
     */
    int findExits(@Param("dimName")String dimName);

    void add(DimData dim);

    void addFromCombination(DimData dim);

    void startOrStop(@Param("state") String state, @Param("dimId") String dimId);

    void update(DimData dim);

    int shareUpdate(DimData dim);

    List<DimData> findList(@Param("theme") String theme, @Param("dimName") String dimName, @Param("department") String department, @Param("state") String state, @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd, @Param("uptTimeStart") String uptTimeStart, @Param("uptTimeEnd") String uptTimeEnd, @Param("catalogList") List<String> catalogIds, @Param("businessDepartment") String businessDepartment);

    List<DimData> findDimsByCatalogId(@Param("catalog_id") String catalogId);

    /**
     * 获取目录下所有标签-除共享的定制标签和组合标签
     * @param date
     * @param catalogId
     * @param userId
     * @param dataTime
     * @return
     */
    List<DimData> findDimVOsByCatalogId(@Param("current") String date, @Param("catalog_id") String catalogId, @Param(
            "userId") String userId, @Param("dataTime") String dataTime);

    List<DimData> findIndexDimVOsByCatalogId(@Param("current") String date, @Param("catalog_id") String catalogId, @Param(
            "userId") String userId, @Param("dataTime") String dataTime,@Param("indexDimList")List<String> indexDimList);


    List<DimData> findIndexCombination(@Param("current") String date,
                                       @Param("userId") String userId,
                                       @Param("dataTime") String dataTime,
                                       @Param("indexDimList")List<String> indexDimList);


    /**
     * 获取目录下所有标签
     * @param date
     * @param catalogId
     * @param userId
     * @return
     */
    List<DimData> findDimVOs(@Param("current")String date, @Param("catalog_id") String catalogId,@Param(
            "userId") String userId);


    void del(@Param("dimId") String dimId);

    /**
     * 查找标签名是否存在
     *
     * @param dimName
     * @return
     */
    String findDimName(@Param("dimName")String dimName);

    void updatePartCustList(@Param("part_cust_list") String filePath, @Param("dim_id") String dimId, @Param("fileDescription") String fileDescription);

    List<DimData> findDimsByCollect(@Param("user_id") String user_id, @Param("theme") String theme, @Param("department") String department, @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd, @Param("uptTimeStart") String uptTimeStart, @Param("uptTimeEnd") String uptTimeEnd, @Param("dimName") String dimName);

    void updateDimDataRunning(@Param("dim_id") String dimId, @Param("is_data_runnning") boolean isDataRunning,
                              @Param("data_state") String dataState);

    List<String> inCatalogList(@Param("dimName") String dimName);

    List<DimData> dimListInMine(@Param("catalog_id") String catalogId, @Param("user_id") String user_id);

    List<DimData> indexDimListInMine(@Param("catalog_id") String catalogId, @Param("user_id") String user_id,@Param("indexDimList")List<String> indexDimList);

    List<DimData> findDimList(@Param("theme") String theme, @Param("dimName") String dimName, @Param("department") String department, @Param("state") String state, @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd, @Param("uptTimeStart") String uptTimeStart, @Param("uptTimeEnd") String uptTimeEnd, @Param("catalogList") List<String> catalogIds, @Param("businessDepartment") String businessDepartment,@Param("userId") String userId);

    List<DimData> findList();

    List<DimData> findSharedDims(@Param("current") String date, @Param("userId") String userId, @Param("dataTime")String dataTime);

    List<DimData> findIndexSharedDims(@Param("current") String date, @Param("userId") String userId, @Param("dataTime")String dataTime,@Param("indexDimList")List<String> indexDimList);

    @Select("select shared_State from dim_data where dim_id = #{dimId}")
    String findSharedState(@Param("dimId") String dimId);

    List<DimData> findPrivateAndSharedList(@Param("current") String date, @Param("theme") String theme, @Param(
            "dimName") String dimName, @Param("department") String department, @Param("state") String state,
                                           @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd,
                                           @Param("uptTimeStart") String uptTimeStart, @Param("uptTimeEnd") String uptTimeEnd,
                                           @Param("catalogList") List<String> catalogIds, @Param("businessDepartment") String businessDepartment,
                                           @Param("userId") String userId, @Param("dataTime")String dataTime,@Param("sensitive") List<DimCatalog> sensitive);

    List<DimData> findPartSharedList(@Param("current") String date, @Param("theme") String theme,
                                     @Param("dimName") String dimName,
                                     @Param("department") String department, @Param("state") String state,
                                     @Param("createTimeStart") String createTimeStart, @Param("createTimeEnd") String createTimeEnd,
                                     @Param("uptTimeStart") String uptTimeStart, @Param("uptTimeEnd") String uptTimeEnd,
                                     @Param("catalogList") List<String> catalogIds, @Param("businessDepartment") String businessDepartment,
                                     @Param("userId") String userId,@Param("dataTime") String dataTime);

    List<DimData> findAllList(@Param("current") String date, @Param("theme") String theme,
                              @Param("dimName") String dimName,
                              @Param("department") String department, @Param("state") String state, @Param("createTimeStart") String createTimeStart,
                              @Param("createTimeEnd") String createTimeEnd, @Param("uptTimeStart") String uptTimeStart,
                              @Param("uptTimeEnd") String uptTimeEnd, @Param("catalogList") List<String> catalogIds,
                              @Param("businessDepartment") String businessDepartment, @Param("userId") String userId,
                              @Param("dataTime") String dataTime,@Param("sensitive") List<DimCatalog> sensitive);

    /**
     * 当为组合或者自定义标签删除时将state状态置为03代表逻辑删除
     * @param dimId
     */
    void updateStateId(String dimId);

    /**
     * 查询数值型标签
     * @param dimName
     * @param dimId
     * @return
     */
    List<DimNumModel> numberDimList(@Param("dimName") String dimName, @Param("dimId") String dimId,@Param("indexDimList")List<String> indexDimList);
}
